text: Properly handle focus moving to a descendent
authorMatthias Clasen <mclasen@redhat.com>
Mon, 24 Aug 2020 22:31:35 +0000 (18:31 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 24 Aug 2020 22:31:35 +0000 (18:31 -0400)
To discriminate between is-focus and contains-focus,
we need to use notify::is-focus. This makes sure
we don't get annoying warnings when the blink_cb
gets triggered on an unfocused entry.

Fixes: #2979
gtk/gtktext.c

index 873dd1df6450665baa0a90c2d529b349a5baf627..a87f21b79821b26b7c0af46f678ba94e14f92f6f 100644 (file)
@@ -326,6 +326,9 @@ static void   gtk_text_snapshot             (GtkWidget        *widget,
                                              GtkSnapshot      *snapshot);
 static void   gtk_text_focus_in             (GtkWidget            *widget);
 static void   gtk_text_focus_out            (GtkWidget            *widget);
+static void   gtk_text_focus_changed        (GtkEventControllerFocus *focus,
+                                             GParamSpec              *pspec,
+                                             GtkWidget               *widget);
 static gboolean gtk_text_grab_focus         (GtkWidget        *widget);
 static void   gtk_text_css_changed          (GtkWidget        *widget,
                                              GtkCssStyleChange *change);
@@ -1894,10 +1897,8 @@ gtk_text_init (GtkText *self)
 
   controller = gtk_event_controller_focus_new ();
   gtk_event_controller_set_name (controller, "gtk-text-focus-controller");
-  g_signal_connect_swapped (controller, "enter",
-                            G_CALLBACK (gtk_text_focus_in), self);
-  g_signal_connect_swapped (controller, "leave",
-                            G_CALLBACK (gtk_text_focus_out), self);
+  g_signal_connect (controller, "notify::is-focus",
+                    G_CALLBACK (gtk_text_focus_changed), self);
   gtk_widget_add_controller (GTK_WIDGET (self), controller);
 
   widget_node = gtk_widget_get_css_node (GTK_WIDGET (self));
@@ -3196,6 +3197,17 @@ gtk_text_focus_out (GtkWidget *widget)
   gtk_text_check_cursor_blink (self);
 }
 
+static void
+gtk_text_focus_changed (GtkEventControllerFocus *controller,
+                        GParamSpec              *pspec,
+                        GtkWidget               *widget)
+{
+  if (gtk_event_controller_focus_is_focus (controller))
+    gtk_text_focus_in (widget);
+  else
+    gtk_text_focus_out (widget);
+}
+
 static gboolean
 gtk_text_grab_focus (GtkWidget *widget)
 {